﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IOBusiness.LinqDB;

namespace IOBusiness.ClassLinq
{
    public class clsLqTours
    {
        SapaDBDataContext objContext = new SapaDBDataContext();
        public List<tblTour> Tour_getByTheLoai(int idTheLoai)
        {
            try
            {
                var select = from tour in objContext.tblTours
                             where tour.TheLoaiID.Equals(idTheLoai)
                             select tour;
                return select.ToList<tblTour>();
            }
            catch (Exception)
            {
                throw;
            }
        }

        public IList<tblTour> Tour_getByDanhMuc(int idDanhMuc)
        {
            try
            {
                var select = from tour in objContext.tblTours
                             where tour.tblTheLoai.MaDanhMuc.Equals(idDanhMuc)
                             select tour;
                return select.ToList<tblTour>();
            }
            catch (Exception)
            {

                throw;
            }

        }


        public List<tblTour> Tour_getByID(int idTour)
        {
            try
            {
                var select = from tour in objContext.tblTours
                             where tour.ID.Equals(idTour)
                             select tour;

                return select.ToList<tblTour>();
            }
            catch (Exception)
            {
                throw;
            }
        }

        public List<tblTour> Tour_getOther(int idTheLoai, int idTour)
        {
            try
            {
                var select = (from tour in objContext.tblTours
                              where tour.TheLoaiID.Equals(idTheLoai) && !tour.ID.Equals(idTour)
                              select tour).Take(5);
                return select.ToList<tblTour>();
            }
            catch (Exception)
            {
                throw;
            }
        }

        public List<tblTour> Tour_getOtherByID(int id)
        {
            try
            {
                var select = from tour in objContext.tblTours
                             where tour.ID.Equals(id)
                             select tour into t
                             from a in objContext.tblTours
                             where a.TheLoaiID.Equals(t.TheLoaiID)
                             && !a.ID.Equals(id)
                             select a;
                return select.ToList<tblTour>();
            }
            catch (Exception)
            {

                throw;
            }

        }

        public List<tblTour> Tour_getRandom()
        {
            try
            {
                var select = (from tour in objContext.tblTours
                             where tour.Hot.Equals(true)
                             select tour).Take(1);

                return select.ToList<tblTour>();
            }
            catch (Exception)
            {
                throw;
            }
        }

    }

}
